using System.Collections;
using UnityEngine;

public class CoinPool : MonoBehaviour
{
    public GameObject coin; //金币预制体
    public float time; //金币生成间隔时间
    void Start()
    {
        StartCoroutine(go());
    }

    IEnumerator go()
    {
        while (true)
        {
            //协程每time秒执行一次
            CreateCoin();
            yield return new WaitForSeconds(time);
        }
    }

    //生成金币
    private void CreateCoin()
    {
        // GameObject gb = Instantiate(coin, transform);//在当前对象处生成一个金币
        // GameObject gb = pool.Get();
        GameObject gb = ObjectPool.Instance.GetObject(coin);
        gb.transform.position = new Vector3(Random.Range(-80f, -67f), Random.Range(3f, 9f));//随机生成位置
    }
}
